package com.fly.demo.web.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "sysrole")
public class SysRole
{
    @Id
    @GenericGenerator(name = "generator", strategy = "native")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer roleId; // 编号
    
    @Column(nullable = false, unique = true)
    private String role; // 角色标识程序中判断使用,如"admin",这个是唯一的:
    
    private String description; // 角色描述,UI界面显示使用
    
    private Boolean available = Boolean.TRUE; // 是否可用,如果不可用将不会添加给用户
    // 角色 -- 权限关系：多对多关系;
    
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "SysRolePermission", joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "permissionId")})
    private List<SysPermission> permissions;
    
    // 用户 - 角色关系定义;
    @ManyToMany
    @JoinTable(name = "SysUserRole", joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "userId")})
    private List<Users> users;// 一个角色对应多个用户
    
    public Integer getRoleId()
    {
        return roleId;
    }
    
    public void setRoleId(Integer roleId)
    {
        this.roleId = roleId;
    }
    
    public String getRole()
    {
        return role;
    }
    
    public void setRole(String role)
    {
        this.role = role;
    }
    
    public String getDescription()
    {
        return description;
    }
    
    public void setDescription(String description)
    {
        this.description = description;
    }
    
    public Boolean getAvailable()
    {
        return available;
    }
    
    public void setAvailable(Boolean available)
    {
        this.available = available;
    }
    
    public List<SysPermission> getPermissions()
    {
        return permissions;
    }
    
    public void setPermissions(List<SysPermission> permissions)
    {
        this.permissions = permissions;
    }
    
    public List<Users> getUsers()
    {
        return users;
    }
    
    public void setUsers(List<Users> users)
    {
        this.users = users;
    }
}